@echo off

set module=%1
set action=%2

if "%module%"=="web" (
	call :buildweb
  if "%action%"=="deploy" (
    call :deployweb
  )
) else if "%module%"=="pdf" (
	call :buildpdf
  if "%action%"=="deploy" (
    call :deploypdf
  )
) else (
  call :buildweb
  call :buildpdf
  if "%action%"=="deploy" (
    call :deployweb
    call :deploypdf
  )
)
exit

:buildweb
@REM call yarn
call yarn build
del dist.tar
"C:\Program Files\7-Zip\7z.exe" a dist.tar dist
exit /b

:buildpdf
cd pdf/web/
@REM call npm install
@REM call npm run lint --fix
call npm run build
@REM cd ../server
@REM call npm install
cd ../
del server.tar
"C:\Program Files\7-Zip\7z.exe" a server.tar server
cd ../
exit /b

:deployweb
scp dist.tar root@10.100.6.30:/opt/web/
ssh root@10.100.6.30 "cd /opt/web/ && rm -rf dist && tar xf dist.tar && docker restart nginx"
exit /b

:deploypdf
scp pdf/server.tar root@10.100.6.30:/opt/bas-server/report/
ssh root@10.100.6.30 "cd /opt/bas-server/report/ && rm -rf server && tar xf server.tar && docker restart baspdf"
exit /b
